package com.maxus.mini.open.api.controller.photo9cell;

import java.util.List;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.dubbo.config.annotation.Reference;
import com.maux.mini.data.api.photo9cell.Photo9CellItemService;
import com.maux.mini.data.api.redis.RedisService;
import com.maux.mini.data.api.user.UserService;
import com.maxus.mini.common.ElumClass.EntityState;
import com.maxus.mini.common.utils.BeanUtilsExtended;
import com.maxus.mini.common.vo.ResBody;
import com.maxus.mini.entity.photo9cell.Photo9CellItem;
import com.maxus.mini.entity.user.User;
import com.maxus.mini.entity.vo.photo9cell.Photo9CellItemVo;
import com.maxus.mini.open.api.controller.BaseController;
import com.maxus.mini.open.api.vo.req.P100016Vo;
import com.maxus.mini.open.api.vo.req.P100017Vo;
import com.maxus.mini.open.api.vo.req.P100018Vo;
import com.maxus.mini.open.api.vo.req.P800010Vo;
import com.maxus.mini.open.api.vo.req.P800011Vo;
import com.maxus.mini.open.api.vo.res.PR100016Vo;
import com.maxus.mini.open.api.vo.res.PR100017Vo;
import com.maxus.mini.open.api.vo.res.PR100018Vo;
import com.maxus.mini.open.api.vo.res.PR800010Vo;
import com.maxus.mini.open.api.vo.res.PR800011Vo;

/**
 * 照片9格项controller
 * 
 * @author wujinsong
 *
 */
@RestController()
@RequestMapping(value = "api/v1.0/Photo9CellItem")
public class Photo9CellItemController extends BaseController {
	@Reference(version = "1.0.0")
	private Photo9CellItemService<Photo9CellItem, Photo9CellItem> photo9CellItemItemService;
	@Reference(version = "1.0.0")
	private RedisService redisService;
	@Reference(version = "1.0.0")
	private UserService<User, User> userService;

	/**
	 * 添加
	 * 
	 * @param req
	 * @return
	 */
	@RequestMapping(value = "add")
	@ResponseBody()
	public ResBody add(P100016Vo req) {
		PR100016Vo retVo = new PR100016Vo();
		User user = userService.find(req.getUserId());

		Photo9CellItem entity = new Photo9CellItem();
		entity.setUser(user);

		photo9CellItemItemService.save(entity);
		retVo.setId(entity.getId());

		return retVo;
	}

	/**
	 * 删除
	 * 
	 * @param req
	 * @return
	 */
	@RequestMapping(value = "delete")
	@ResponseBody()
	public ResBody delete(P100017Vo req) {
		PR100017Vo retVo = new PR100017Vo();

		Photo9CellItem entity = photo9CellItemItemService.find(req.getId());
		entity.setEntityState(EntityState.D.name());
		photo9CellItemItemService.save(entity);

		return retVo;
	}

	/**
	 * 修改
	 * 
	 * @param req
	 * @return
	 */
	@RequestMapping(value = "update")
	@ResponseBody()
	public ResBody update(P100018Vo req) {
		PR100018Vo retVo = new PR100018Vo();

		Photo9CellItem entity = photo9CellItemItemService.find(req.getId());
		BeanUtilsExtended.copyProperties(entity, req);

		photo9CellItemItemService.save(entity);

		return retVo;
	}

	/**
	 * 单个查询
	 * 
	 * @param req
	 * @return
	 */
	@RequestMapping(value = "findOne")
	@ResponseBody()
	public ResBody findOne(P800010Vo req) {
		PR800010Vo retVo = new PR800010Vo();

		Photo9CellItem entity = photo9CellItemItemService.find(req.getId());
		retVo.setDetail(entity);

		return retVo;
	}

	/**
	 * 分页查询
	 * 
	 * @param req
	 * @return
	 */
	@RequestMapping(value = "page")
	@ResponseBody()
	public ResBody page(P800011Vo req) {
		PR800011Vo retVo = new PR800011Vo();
		List<Photo9CellItem> entities = null;

		Photo9CellItemVo vo = new Photo9CellItemVo();
		try {
			BeanUtilsExtended.copyProperties(vo, req);
			entities = photo9CellItemItemService.page(vo).getContent();
		} catch (Exception e) {
			System.out.println(e.getMessage());
		}

		retVo.setItemVos(entities);

		return retVo;
	}
}
